<%= turbo_frame_tag "project_dependent_fields", data: {
    update_url: form_projects_dependent_fields_time_entries_url,
    request_param_name: 'project_id'
  } do %>
  <% time_entry = form.object %>

  <div class="fieldset flex flex-col tour--issue-selection">
    <div class="flex justify-between items-center">
      <%= form.label :issue, TimeEntry.human_attribute_name(:issue), class: "fieldset-label" %>

      <% if time_entry.project.present? %>
        <%= link_to project_issues_path(time_entry.project),
                    class: "link link-hover flex items-center gap-1",
                    tabindex: '-1',
                    data: {
                      turbo_frame: "_top",
                      time_entry__form_target: "allIssuesLink"
                    } do %>
          <%= t("nav.all_issues") %>
          <i class="opacity-70 ti ti ti-arrow-up-right"></i>
        <% end %>

        <%= link_to '',
                    class: "link link-hover flex items-center gap-1 hidden",
                    tabindex: '-1',
                    data: {
                      issue_url: project_show_issue_path(time_entry.project, 'REPLACE_WITH_ISSUE_ID'),
                      turbo_frame: "_top",
                      time_entry__form_target: "issueLink"
                    } do %>
          <%= t("actions.go_to_issue") %>
          <i class="opacity-70 ti ti ti-arrow-up-right"></i>
        <% end %>
      <% end %>
    </div>

    <% if time_entry.project.present? %>
      <% if time_entry.project.issues.any? %>
        <%
          issues_for_select = time_entry.project.issues.active.order(title: :asc).to_a

          if time_entry.persisted? and time_entry.issue&.archived?
            issues_for_select.push(time_entry.issue)
          end
        %>
        <%= select_tag "time_entry[issue_id]",
            options_from_collection_for_select(issues_for_select, :id, :title, time_entry.issue_id),
            {
              include_blank: t('none_selected_f'),
              style: "width: 100%",
              data: {
                controller: "select2",
                time_entry__form_target: 'issuesSelect',
                action: "change->time-entry--form#toggleIssueLinks"
              }
            } %>
      <% else %>
        <p class="text-sm italic"><%= t(".project_has_no_issue") %></p>
      <% end %>
    <% else %>
      <p class="text-sm italic fieldset-label"><%= t(".select_a_project") %></p>
    <% end %>
  </div>
<% end %>